// Pass an image and have width returned
function getImageWidth(myImage) {
	var x, obj;
	if (document.layers) {
		var img = getImage(myImage);
		return img.width;
	} else {
		return getElementWidth(myImage);
	}
	return -1;
}

// Pass an image and have heightreturned
function getImageHeight(myImage) {
	var y, obj;
	if (document.layers) {
		var img = getImage(myImage);
		return img.height;
	} else {
		return getElementHeight(myImage);
	}
	return -1;
}

// Data unpacks to redirectUrl and isLoggedInUrl
var SSO = { 

	debug : true,
	verbose : true,
	loggedInImage : new Image(),
	redirectUrl : null,
	isLoggedInUrl : null,
	iframe : null,
	status : null,

	'init' : function(redirectUrl, isLoggedInUrl) {
		if (this.verbose)
		{
			YAHOO.log("redirectUrl " + redirectUrl + ". isLoggedInUrl " + isLoggedInUrl);
		}
		this.redirectUrl = redirectUrl;
		this.isLoggedInUrl = isLoggedInUrl;
	},

	'isLoggedIn' : function() {
		this.loggedInImage = new Image();
		this.loggedInImage.id = "loggedInImage";
		this.loggedInImage.src = this.isLoggedInUrl;
		this.loggedInImage.onload = SSO.checkLoggedInImage();
		YAHOO.lang.later(30000, SSO, "isLoggedIn", null, true);
	},

	'checkLoggedInImage' : function() {
		var ssoDiv = document.getElementById("ssoDiv");

		if (this.loggedInImage.width == 1)
		{
			ssoDiv.innerHTML = "<H2>Logged in</H1>";
			YAHOO.log("Logged in");

			if (document.getElementById("outlookLive") == null)
			{
				var button = document.createElement("INPUT");
				button.type = "button";
				button.value = "Outlook Live";
				button.title = "b";
				button.style.fontWeight = "bold";
				button.id = "outlookLive";
				button.onclick = function()
				{
					window.open("http://www.outlook.com","outlook.com", "menubar=1,location=0,menubar=0,directories=0,resizable=1,width=1024,height=768");
				};
				ssoDiv.appendChild(button);
			}
		}
		else
		{
			ssoDiv.innerHTML = "<H2>Not logged in</H1>";

			if (this.status == "loggingIn") {
				if (this.verbose) {
					YAHOO.log("In the middle of a login attempt, blocking...");
				}		
			}		
			else if (document.createElement && (iframe = document.createElement("iframe"))) 
			{
				if (this.verbose) {
					YAHOO.log("Begin login attempt");
				}		
				this.status = "loggingIn";
				iframe.name = "ssoFrame";
				iframe.id = "ssoFrame";
				iframe.src = this.redirectUrl;
				iframe.height = 0;
				iframe.width = 0;
				iframe.onload = function() {
					if (this.loggedInImage.width == 1) 
					{
						this.status = "loggedIn";
					}
					else
					{
						ssoDiv.innerHTML = "<H2>Not logged in</H2>";
						this.status = "notLoggedIn";
					}
				}
				ssoDiv.appendChild(iframe);
			}
		}
	}
}

